package  
{
	import flare.basic.*;
	import flare.core.*;
	import flare.materials.*;
	import flare.materials.layers.*;
	import flash.display.*;
	import flash.events.*;
	
	[SWF(frameRate = 120, backgroundColor = 0x808080, width = 800, height = 600 )]
	/**
	 * ...
	 * @author Ariel Nehmad
	 */
	public class Test14_Shaders extends Sprite
	{
		private var scene:Scene3D;
		private var shader:Shader3D;
		private var model:Pivot3D;
		
		public function Test14_Shaders() 
		{
			// creates and load the scene as a normal.
			scene = new Viewer3D( this );
			scene.addEventListener( Scene3D.COMPLETE_EVENT, completeEvent );
			scene.defaultLight.setRotation( 45, -45, 45 );
			
			// load some textures.
			var texture0:Texture3D = scene.addTextureFromFile( "textures/AXTruck.png" );
			var texture1:Texture3D = scene.addTextureFromFile( "textures/cell01mod.png" );
			
			// create a new dynamic shader.
			shader = new Shader3D( "test_shader" );
			
			// this is the first layer, 
			// the blend mode will be ignored because there is no previous channel to blend with.
			shader.layers.push( new TextureMapLayer( texture0 ) );
			// add a light channel. (aditionally you can set a blendMode and alpha value).
			shader.layers.push( new LightLayer( scene.defaultLight ) );
			// add another layer, this time, and environment layer with any of flash blend modes and an alpha/opacity.
			// the alpha/opacity act as a multipler value aditional to the blend mode, before the blending operation.
			// so you can set any value, from 0 to n...
			shader.layers.push( new EnvironmentMapLayer( texture1, BlendMode.MULTIPLY, 2.5 ) );
			// add some tint.
			shader.layers.push( new ColorLayer( 1, 0.7, 0.7, 1, BlendMode.MULTIPLY ) ); 
			// etc...etc...and finally compile the shader.
			shader.build();
			
			model = scene.addChildFromFile( "ax.f3d" );
		}
		
		private function completeEvent(e:Event):void
		{
			// needs to wait to complete event to apply the new materials.
			model.setMaterial( shader );
			
			scene.camera.zoom = 0.5;
		}
	}
}